package top.aicats.pattern.dynamicProxy.GP;

import java.lang.reflect.Method;

public class GPMeiPo implements GPInvocationHandler {

    private Object target;

    public Object getInstance(Object object)throws Exception {
        this.target = object;
        Class<?> clazz =target.getClass();
        return GPProxy.newProxyInstance(new GPClassLoader(), clazz.getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object obj =method.invoke(this.target, args);
        after();
        return obj;
    }

    @Override
    public Object invoke2(Object proxy, Method method, Object[] args) throws Throwable {
        before1();
        Object obj =method.invoke(this.target, args);
        after1();
        return obj;
    }

    private void after1() {
        System.out.println("之后1");
    }

    private void before1() {
        System.out.println("之前1");
    }

    private void after() {
        System.out.println("之后");
    }

    private void before() {
        System.out.println("之前");
    }
}
